<%@page import="com.dfhc.bus.busmessage.IMessageConstants" %>
<%@page import="com.dfhc.bus.busmessagerecipients.IMessageRecipientsConstants" %>
<%@page import="com.dfhc.util.StringHelper"%>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />

<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %>
<title>添加消息收件人 </title>

<%@ taglib uri="/dfhc" prefix="dfhc" %>
</head>
<body>


<article class="page-container">

<!-- 消息表参照 -->
<dfhc:div templateId="h_ui_div_reference" id="messageIdContent">
	<form name="searchForm" id="searchForm" action="">
	<dfhc:div templateId="h_ui_div_search">
		<dfhc:input templateId="h_ui_search_input" placeholder="输入xxx、xxx、xxx" id="" name="searchName"/>
		<dfhc:button templateId="h_ui_search_button" id="" name="" onclick="javascript:_searchData($('#messageIdTable').DataTable());" />
	</dfhc:div>
	</form>
    	<dfhc:table templateId="table_h_ui" id="messageIdTable" >    	
		<dfhc:thead>
			<dfhc:tr> 
				<dfhc:th width="25">
<%-- 				   <dfhc:checkbox name="allId"    /> --%>
				</dfhc:th>	
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IMessageConstants.TABLE_COLUMN_DISPLAY.get("title")%></dfhc:title>
				</dfhc:th>
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IMessageConstants.TABLE_COLUMN_DISPLAY.get("content")%></dfhc:title>
				</dfhc:th>
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IMessageConstants.TABLE_COLUMN_DISPLAY.get("expirationTime")%></dfhc:title>
				</dfhc:th>
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IMessageConstants.TABLE_COLUMN_DISPLAY.get("messageType")%></dfhc:title>
				</dfhc:th>
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IMessageConstants.TABLE_COLUMN_DISPLAY.get("messageDisplayType")%></dfhc:title>
				</dfhc:th>
			</dfhc:tr>
    	   </dfhc:thead>			
	</dfhc:table>           
</dfhc:div>








	<form action="" method="post" class="form form-horizontal" id="form-busmessagerecipients-add">
	   <input type="hidden" id="id" name="id" value="${bean.id}">
							
							
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=StringHelper.replaceAll(IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("messageId"),"ID","")%>：</dfhc:title>	    
	    <dfhc:div templateId="h_ui_div_fromcontrol">	        
			<dfhc:input templateId="h_ui_input" value="${bean.messageId}" placeholder='<%=StringHelper.replaceAll("点击选择"+IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("messageId"),"ID","")%>' id="messageId" name="messageId" readonly="true"/>
	    </dfhc:div>	    		 
	  </dfhc:div>
							
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><%=IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("recipientId")%>：</dfhc:title>	    
	    <dfhc:div templateId="h_ui_div_fromcontrol">	        
			<dfhc:input templateId="h_ui_input" value="${bean.recipientId}" placeholder="" id="recipientId" name="recipientId"/>			
	    </dfhc:div>	    		 
	  </dfhc:div>
							
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><%=IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("recipient")%>：</dfhc:title>	    
	    <dfhc:div templateId="h_ui_div_fromcontrol">	        
			<dfhc:input templateId="h_ui_input" value="${bean.recipient}" placeholder="" id="recipient" name="recipient"/>			
	    </dfhc:div>	    		 
	  </dfhc:div>
							
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><%=IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("orderTaskId")%>：</dfhc:title>	    
	    <dfhc:div templateId="h_ui_div_fromcontrol">	        
			<dfhc:input templateId="h_ui_input" value="${bean.orderTaskId}" placeholder="" id="orderTaskId" name="orderTaskId"/>			
	    </dfhc:div>	    		 
	  </dfhc:div>
							
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><%=IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("orderNum")%>：</dfhc:title>	    
	    <dfhc:div templateId="h_ui_div_fromcontrol">	        
			<dfhc:input templateId="h_ui_input" value="${bean.orderNum}" placeholder="" id="orderNum" name="orderNum"/>			
	    </dfhc:div>	    		 
	  </dfhc:div>
							
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("messageStatus")%>：</dfhc:title>	    
			<dfhc:div templateId="h_ui_div_fromcontrol">
				<dfhc:select templateId="h_ui_select" size="1" name="messageStatus" id="messageStatus" pleaseSelect="1" defaultValue="${bean.messageStatus}" sqlOption="code" code="MESSAGE_STATUS" />				
			</dfhc:div>
	  </dfhc:div>
							
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><%=IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("receivingTime")%>：</dfhc:title>	    
            <dfhc:div templateId="h_ui_div_fromcontrol">	        
			<dfhc:input templateId="h_ui_timestamp_input" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="${bean.receivingTime}" id="receivingTime" name="receivingTime" readonly="true"/>
	    </dfhc:div>	    		 
	  </dfhc:div>
							
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><%=IMessageRecipientsConstants.TABLE_COLUMN_DISPLAY.get("sendFlag")%>：</dfhc:title>	    
			<dfhc:div templateId="h_ui_div_fromcontrol">
				<dfhc:select templateId="h_ui_select" size="1" name="sendFlag" id="sendFlag" pleaseSelect="1" defaultValue="${bean.sendFlag}" sqlOption="code" code="RM_YES_NOT" />				
			</dfhc:div>
	  </dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:div templateId="h_ui_div_pop_up_button">
				<dfhc:button templateId="h_ui_submit_button" />
			</dfhc:div>
		</dfhc:div>
	</form>
</article>



<script type="text/javascript">
var _table;
$(function(){
	//获取新id
	<c:if test="${empty bean}"> 
	$('#id').val(getNewId('<%=IMessageRecipientsConstants.TABLE_NAME%>'));
	</c:if>

	//点击选择消息表
    $("#messageId").on('focus',function(){
    	var messageIdObj = $("#messageId");
    	var messageIdContentObj = $("#messageIdContent");
    	var messageIdOffset = messageIdObj.offset();
    	var top = (messageIdOffset.top + messageIdObj.outerHeight()-messageIdContentObj.outerHeight())+"px";    	
    	$("#messageIdContent").css({
    	left:messageIdOffset.left+"px",
    	top:(messageIdOffset.top +messageIdObj.outerHeight())+"px",
    	display:"block",
    	width:(messageIdObj.outerWidth()-3)+"px",    	    
    	}).slideDown("fast");
    	
    	$("body").bind("mousedown",function(){
    	   if(!(event.target.id =="messageIdContent" || $(event.target).parents("#messageIdContent").length>0)){
    	   $("#messageIdContent").css({
    		left:0,
    		top:0,
    		display:"none",
    		width:0
    	   }).fadeOut("fast");
    	   }
    	});
    });	

    _table = $('#messageIdTable').dataTable({	
	     dom: 'Zlfrtip',	   		
		 ajax : function(data, callback, settings) {
		       var param =  splitParameter(data); 
                $.ajax({  
                        type: "GET",  
                        url: getRootPath()+"/busmessage/ajaxList?jsguid=<%=session.getId()%>",  
                        cache : false,  //禁用缓存  
                        data:param,   
                        dataType: "json",  
                        success: function(result) {  
                                //异常判断与处理  
                                if (result.status=='0') {  
                                    alert(result.message);  
                                    return;  
                                }  
                                //封装返回数据  
                                var returnData = {};  
                                returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回  
                                returnData.recordsTotal = result.recordsTotal;//总记录数  
                                returnData.recordsFiltered = result.recordsTotal;//后台不实现过滤功能，每次查询均视作全部结果  
                                returnData.data = result.data;  
                                //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染  
                                //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕  
                                callback(returnData);  
                                //更新总记录数
                                $("#totalRecodSpan").html('共有数据：<strong>'+result.recordsTotal+'</strong> 条</span>');
                        },  
                        error: function(XMLHttpRequest, textStatus, errorThrown) {  
                            alert("查询失败");  
                        }  
                    });  
            },  
		"columns": [
		  {
		    "data":"id",
			"render":function(data,type,row,meta){
			   var content='<input type="checkbox" name="allId" value="'+row.id+'"/>';
			   return content; 
			}
		  },
		  {"data":"title"},
		  {"data":"content"},
		  {	   
		    "data":"expirationTime",
		    "defaultContent":"",
		    render:function(data,type,row,meta){
		    var content=formatDate(row.expirationTime,'yyyy-MM-dd HH:mm:ss');			 
		    return content; 
		  }
		  },
		  {"data":"messageType"},
		  {"data":"messageDisplayType"}
		],
		"columnDefs": [ {"searchable": false,
            "orderable": false,
            "targets": 0 }]  				
	}); 
	//参照表格check box 绑定值变更
	_table.delegate($("input[name=allId]"),"change",function(){
	//判断用户是否选择
	var len = $('input[name="allId"]:checked').length;
	var count=0;
	var ids='';
	$('input[name="allId"]:checked').each(function(){
     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=""
         	}
         	count++;
     	}
       });  
      
    
      if(count>1){
       alert("只能选择一条记录!");
       return;	
      }
      if(count==1){
    	//回填消息ID
    	$("#messageId").val(ids);
    	//隐藏表格
    	$("#messageIdContent").css({
    		left:0,
    		top:0,
    		display:"none",
    		width:0
    	   }).fadeOut("fast");
      }else if(count ==0){
        //回填消息ID
    	$("#messageId").val('');
      }    	   
	});	

	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-busmessagerecipients-add").validate({
		rules:{
			recipient:{			
				maxlength:200
			},
			orderNum:{			
				maxlength:19
			},
			messageStatus:{			
				required:true,
				minlength:1,
				maxlength:2
			},
			receivingTime:{			
			},
			sendFlag:{			
				maxlength:1
			}
		},
 		messages: {
			recipient:{
		        maxlength: "接收人最大长度为200个字母"
	           },
			orderNum:{
		        maxlength: "接收订单编号最大长度为19个字母"
	           },
			messageStatus:{
		        required: "请输入消息状态",
		        minlength: "消息状态至少由1个字母组成",
		        maxlength: "消息状态最大长度为2个字母"
	           },
			receivingTime:{
	           },
			sendFlag:{
		        maxlength: "是否已发送最大长度为1个字母"
	           }
	    },		
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			<c:if test="${empty bean}"> 
			var url = getRootPath()+"/busmessagerecipients/insert?jsguid="+$('#id').val();
			</c:if>
			<c:if test="${not empty bean}"> 
			var url = getRootPath()+"/busmessagerecipients/update?jsguid="+$('#id').val();
			</c:if>
			//提交成功关闭
			submitAjax(url,$("#form-busmessagerecipients-add").serialize()); 		    		    		
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
